<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- a标签的默认行为 -->
    <a href="https://baidu.com" id="baidu">百度</a>

    <!-- 表单的默认行为 -->
    <form action="index.php" id="registry">
      用户名：<input type="text" /> <br />
      <input type="submit" value="注册" />
    </form>

    <script>
      var aEle = document.getElementById('baidu');
      aEle.addEventListener('click', function (event) {
        // 事件对象阻止默认行为
        event.preventDefault();
        alert('百度');
      });

      var formEle = document.getElementById('registry');
      //   给表单绑定表单提交事件 onsubmimt
      formEle.addEventListener('submit', function (event) {
        event.preventDefault();
        alert('表单提交了');
      });
    </script>
  </body>
</html>
